package main;

import script.Script;
import define.Config;
import define.ErrorDefine;
import excelBase.ExcelFile;

public class ErrorException extends Exception
{
	private static final long serialVersionUID = 1L;
	
	private ErrorDefine m_error;
	private String m_makeup;
	private int m_position;
	private Script m_errorScript;
	private ExcelFile m_errorExcel;
	
	public ErrorException(String scriptName, ErrorDefine error)
	{
		super();
		m_error = error;
		m_makeup = null;
		m_position = Config.NO_POSITION;
		m_errorScript = ErrorHandler.m_errorScript;
		m_errorExcel = ErrorHandler.m_errorExcel;
	}
	
	public ErrorException(ErrorDefine error, int position) 
	{
		super();
		m_error = error;
		m_makeup = null;
		m_position = position;
		m_errorScript = ErrorHandler.m_errorScript;
		m_errorExcel = ErrorHandler.m_errorExcel;
	}
	
	public ErrorException(ErrorDefine error, String makeup)
	{
		super();
		m_error = error;
		m_makeup = makeup;
		m_errorScript = ErrorHandler.m_errorScript;
		m_errorExcel = ErrorHandler.m_errorExcel;
		m_position = Config.NO_POSITION;
	}
	
	public ErrorException(ErrorDefine error, String makeup, int position)
	{
		super();
		m_error = error;
		m_makeup = makeup;
		m_position = position;
		m_errorScript = ErrorHandler.m_errorScript;
		m_errorExcel = ErrorHandler.m_errorExcel;
	}
	
	public String getMessage()
	{
		String name = "";
		if(m_errorScript != null)
		{
			name = "excel: " + m_errorScript.getExcel().getName() + "   script: " + m_errorScript.getName() + "\n";
		}
		else if(m_errorExcel != null)
		{
			name = "excel: " + m_errorExcel.getName() + "\n";
		}
		return name + "error: " + m_error.getMessage() + (m_makeup == null ? "" : ": " + m_makeup);
	}
	
	public int getErrorId()
	{
		return m_error.getId();
	}
	
	public int getPosition()
	{
		return m_position;
	}
}
